import { createStore } from 'vuex'
import { IRootState } from './types'
import { LoginModule } from './login'
import LocalCache, { CacheKey } from '@/utils/cache'
const store = createStore<IRootState>({
  modules: {
    LoginModule
  },
  state: () => {
    return {}
  }
})
export default store
export function storeInit() {
  const Token = LocalCache.getItem(CacheKey.TOKEN)
  const userInfo = LocalCache.getItem(CacheKey.USER_INFO)
  const roleMenu = LocalCache.getItem(CacheKey.ROLE_MENU)

  Token && store.commit('LoginModule/setToken', Token)
  roleMenu && store.commit('LoginModule/setRoleMenu', roleMenu)
  userInfo && store.commit('LoginModule/setUserInfo', userInfo)
}
